import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { h } from 'vue';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';

export function getBasicColumns() : BasicColumn[] {
	return [
		{
			title: '出发日期',
			dataIndex: 'markDate',
			width: 80,
		},
		{
			title: '星期几',
			dataIndex: 'week',
			width: 30,
		},
		{
			title: '￥/人',
			dataIndex: 'startPrice',
			width: 80,
		},
		/* {
			title: '天数',
			dataIndex: 'days',
			width: 20,
		}, */
	];
}





export function getBasicColumnsTourRoute() : BasicColumn[] {
	return [
		{
			title: '第几天',
			dataIndex: 'dayNum',
			width: 80,
		},
		{
			title: '景点',
			dataIndex: 'scenics',
			customRender: ({ text }) => {
				let content = '', str = '';
				for (let i = 0; i < text.length; i++) {
					content += `<div>${text[i].title},排序：${text[i].sort},默认：${text[i].isDefault};</div> `
					// str += text[i].title + ",排序：" + text[i].sort + ",默认：" + text[i].isDefault+";"
				}
				//  return str
				// console.log('======>', content)
				return h('p', {
					innerHTML: content
				})
			}
		},
	];
}
//表单数据
export const formSchema : FormSchema[] = [
	{
		label: '出发日期',
		field: 'markDate',
		component: 'DatePicker',
		componentProps: {
			showTime: false,
			valueFormat: 'YYYY-MM-DD'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择开始日期!' },
			];
		},
	},
	{
		label: '星期几',
		field: 'week',
		component: 'Input',
		required: true,
		dynamicDisabled: ({ values }) => {
			return true;
		},
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.markDate) {
				let week = new Date(formModel.markDate).getDay()
				if (week == 0) {
					formModel.week = '周日'
				} else if (week == 1) {
					formModel.week = '周一'
				} else if (week == 2) {
					formModel.week = '周二'
				} else if (week == 3) {
					formModel.week = '周三'
				} else if (week == 4) {
					formModel.week = '周四'
				} else if (week == 5) {
					formModel.week = '周五'
				} else if (week == 6) {
					formModel.week = '周六'
				}
			}

		},
	},
	{
		label: '单价/人',
		field: 'startPrice',
		component: 'Input',
		required: true
	},
	/* {
		label: '游玩天数',
		field: 'days',
		component: 'Input',
		required: true
	}, */
];

export function getCountOrUpdateRulesColumns() : BasicColumn[] {
	return [

		{
			title: '从多少小时',
			dataIndex: 'soTime',
			width: 80,
		},
		{
			title: '到多少小时',
			dataIndex: 'toTime',
			width: 80,
		},
		{
			title: '从多少公里',
			dataIndex: 'soKm',
			width: 150,
		},
		{
			title: '到多少公里',
			dataIndex: 'toTime',
			width: 180,
		},
		{
			title: '状态',
			dataIndex: 'stats',
			width: 180,
			customRender: ({ text }) => {
				if (text == 'tension') return '紧张'
				if (text == 'easy') return '轻松'
				if (text == 'comfort') return '舒适'
			}
		},

	];
}
export const formSchemaCountOrUpdate : FormSchema[] = [

	{
		label: '状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '舒适', value: "comfort" },
				{ label: '轻松', value: "easy" },
				{ label: '紧张', value: "tension" },
			]
		},
		required: true,
	},
	{
		label: '从多少小时',
		field: 'soTime',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /(^[1-9]\d*$)/, message: '请输入正确的小时!' },
			];
		},
	},
	{
		label: '到多少小时',
		field: 'toTime',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /(^[1-9]\d*$)/, message: '请输入正确的小时!' },
			];
		},
	},
	{
		label: '从多少公里',
		field: 'soKm',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^([0-9]{1,2}|100)$/, message: '请输入正确的公里!' },
			];
		},
	}, {
		label: '到多少公里',
		field: 'toKm',
		required: true,
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^([0-9]{1,2}|100)$/, message: '请输入正确的公里!' },
			];
		},
	},
];


export function getRefundOrUpdateRulesColumns() : BasicColumn[] {
	return [
		{
			title: '排序',
			dataIndex: 'sort',
			width: 80,
		},
		{
			title: '从多少小时',
			dataIndex: 'startTime',
			width: 80,
		},
		{
			title: '到多少小时',
			dataIndex: 'toTime',
			width: 80,
		},
		{
			title: '退款比例(百分比)',
			dataIndex: 'refundRatio',
			width: 150,
		},
		{
			title: '修改出发日期付款金额',
			dataIndex: 'updateDayPrice',
			width: 180,
		},

	];
}
export const formSchemaRefundOrUpdate : FormSchema[] = [
	{
		label: '排序',
		field: 'sort',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^[1-9]d*$/, message: '请输入正确的排序!' },
			];
		},
	},
	{
		label: '从多少小时',
		field: 'startTime',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /(^[1-9]\d*$)/, message: '请输入正确的小时!' },
			];
		},
	},
	{
		label: '到多少小时',
		field: 'toTime',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /(^[1-9]\d*$)/, message: '请输入正确的小时!' },
			];
		},
	},
	{
		label: '退款比例(百分比)',
		field: 'refundRatio',
		component: 'Input',
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^([0-9]{1,2}|100)$/, message: '请输入正确的退款比例!' },
			];
		},
	}, {
		label: '修改出发日期付款金额',
		field: 'updateDayPrice',
		required: true,
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^(([0-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
			];
		},
	},
];

export function getCarPriceData() : BasicColumn[] {
	return [
		{
			title: '车型',
			dataIndex: 'carTitle',
			width: 80,
		},
		{
			title: '最低多少人',
			dataIndex: 'leastUserNum',
			width: 80,
		}, {
			title: '最大多少人',
			dataIndex: 'bigUserNum',
			width: 80,
		}, 
	];
}

export const formSchemaQrCode : FormSchema[] = [
	{
		label: '二维码',
		field: 'qrCode',
		required: true,
		component: 'JUpload',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 1,
		},
	},
	{
		label: '地址',
		field: 'url',
		component: 'Input',
		slot:'urlAddress',
		required: true
	},

];
export const formSchemaCarPrice : FormSchema[] = [
	{
		label: '车型',
		field: 'carTitle',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: 'BS_PreTravelCarPrice,levelTitle,id,dayNum=3'
		},
		required: true
	},
	{
		label: '最低多少人',
		field: 'leastUserNum',
		component: 'InputNumber',
		required: true
	},
	{
		label: '最大多少人',
		field: 'bigUserNum',
		component: 'InputNumber',
		required: true
	},
];

export function getBasicColumnsPrice() : BasicColumn[] {
	return [
		{
			title: '从多少人',
			dataIndex: 'minNum',
			width: 80,
		},
		{
			title: '到多少人',
			dataIndex: 'maxNum',
			width: 30,
		},
		{
			title: '单价￥/人',
			dataIndex: 'price',
			width: 80,
		}
	];
}
//表单数据
export const formSchemaPrice : FormSchema[] = [
	{
		label: '从多少人',
		field: 'minNum',
		component: 'Input',
		required: true
	},
	{
		label: '到多少人',
		field: 'maxNum',
		component: 'Input',
		required: true
	},
	{
		label: '价格/人',
		field: 'price',
		component: 'Input',
		required: true
	},
];
export const formSchemaXgScenicPoint : FormSchema[] = [
	/* 	{
			label: '所在城市',
			field: 'cityId',
			component: 'JTreeDict',
			componentProps: { async: true, parentCode: 'A02' },
		}, */
	{
		label: '景点',
		field: 'scenicidS',
		component: 'JCheckbox',
		componentProps: {
			dictCode: 'BS_Scenic,title,id',
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择景区!' },
			];
		},
	},

];


export const formToHomePage : FormSchema[] = [
	{
		label: '排序',
		field: 'sort',
		component: 'InputNumber',
		required: true
	},
	{
		label: '类别选择',
		field: 'typeAcitvity',
		component: 'InputNumber',
		slot: 'selectTypes',
		required: true
	},
	{
		label: '',
		field: 'activityTypes',
		component: 'Input',
		show: false
	},
	{
		label: '',
		field: 'mainId',
		component: 'Input',
		show: false
	},

];
export function getBasicColumnsTourist() : BasicColumn[] {
	return [
		{
			title: '姓名',
			dataIndex: 'userName',
			width: 80,
		},
		{
			title: '手机号',
			dataIndex: 'phone',
			width: 30,
		},
		{
			title: '身份证',
			dataIndex: 'idCard',
			width: 80,
		},
		{
			title: '是否已签合同',
			dataIndex: 'isSign',
			width: 80,
			customRender: ({ text }) => {
				if (text == 1) {
					return '已签'
				} else {
					return '未签'
				}
			}
		}
	];
}

export const formToTourist : FormSchema[] = [
	{
		label: '姓名',
		field: 'userName',
		component: 'Input',
		required: true
	},
	{
		label: '手机',
		field: 'phone',
		component: 'Input',
		required: true
	},
	{
		label: '身份证',
		field: 'idCard',
		component: 'Input',
		required: true
	},
	{
		label: '所在城市',
		field: 'cityId',
		component: 'JTreeDict',
		componentProps: { async: true, parentCode: 'A02' },
	},
	{
		label: '合同',
		field: 'isSign',
		component: 'JDictSelectTag',
		required: true,
		componentProps: {
			options: [
				{ label: '是', value: '1' },
				{ label: '否', value: '0' }
			]
		}
	},
	{
		label: '',
		field: 'activityTypes',
		component: 'Input',
		show: false
	},


];
/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}